﻿/********************************************************************************/
/* 	stage.d																		*/
/*------------------------------------------------------------------------------*/
/*	製作		（　゜ワ゜）ノ　／　松久貫太									*/
/*	製作開始　	2007/11/22														*/
/*	MAIL		omega@personal.email.ne.jp										*/
/*	URL		http://nagoya.cool.ne.jp/o_mega										*/
/*																				*/
/*	このソースは「やわらかライセンス」の元で配布されています。					*/
/*-更新履歴---------------------------------------------------------------------*/
/*	2007/--/--																	*/
/*-その他-----------------------------------------------------------------------*/
/*	なし																		*/
/********************************************************************************/

/* ライブラリのインポート *******************************************************/
private import screen;
private import player;
private import shot;
private import enemy;
private import vector;
private import effect;
private import actor;
private import state;

private import std.string;
private import std.math;
private import std.math2;

private import defines;
private import hell2;

class Stage{
	this(){}
	
	abstract void update();
	abstract void draw();
	abstract bool isFinish();
	abstract int getTotalFrame();
}

// -------------------------------------------------------------------
class TestStage : Stage{
	class ScriptLine{
		string command;
		int framewait;
		double param[];
		
		static int PARAM_MAX = 4;
		
		this(){
			command = "";
			framewait = 0;
			param = new double[PARAM_MAX];
			foreach(inout p;param) p = 0;
		}
	}
	
	GameMain gamemain;
	
	ScriptLine slines[];
	int wait;
	int ptr;
	int total_frame;
	
	bool _isFinish;
	
	static const char[] filename = "teststage.dat";
	
	this(GameMain gm){
		gamemain = gm;
		
		wait = 0;
		ptr = -1;
		_isFinish = false;
		load(filename);
	}
	
	void load(char[] file){
		string[] buf = split(cast(string)std.file.read(file) , "\n");
		
		slines = new ScriptLine[buf.length];
		
		total_frame = 0;
		for(int ln=0;ln < buf.length;ln++){
			string[] item = split(buf[ln] , ",");
			slines[ln] = new ScriptLine();
			
			for(int t=0;t<item.length;t++){
				if(t == 0){
					slines[ln].framewait = cast(int)std.string.atoi(item[t]);
					total_frame += cast(int)std.string.atoi(item[t]);
				}
				if(t == 1) slines[ln].command = item[t];
				if(t >= 2) slines[ln].param[t-2] = cast(double)std.string.atof(item[t]);
			}
		}
	}
	
	void update(){
		if(wait > 0){
			wait--;
			return;
		}
		
		ptr++;
		if(ptr >= slines.length) {
			wait = 999999;
			_isFinish = true;
			return;
		}
		ScriptLine sline = slines[ptr];
		
		wait = sline.framewait - 1;
		if(std.string.find(sline.command , "enemy") > -1){
			gamemain.enemyactor.add(
				new Vec3(sline.param[0] , sline.param[1] , CHAR_Z_SURFACE),
				new Vec3(sline.param[2] , sline.param[3] , 0),
				new EnemySpec(EnemySpec.TYPE.TANK));
		}
	}
	
	void draw(){
	}
	
	bool isFinish(){
		return _isFinish;
	}
	
	int getTotalFrame(){
		return total_frame;
	}
}

